import Vue from 'vue'
import App from './App'
import store from './store'
import ajax from './common/js/ajax.js'
import myLoading from '@/components/loading/index.vue'
import mySwiper from '@/components/my-swiper/src/index.vue'

Vue.config.productionTip = false

App.mpType = 'app'
Vue.prototype.$store = store
Vue.prototype.$ajax=ajax

Vue.component('myLoading',myLoading)
Vue.component('mySwiper',mySwiper)

// #ifdef H5
var jweixin = require('jweixin-module')
Vue.prototype.$jweixin=jweixin
window.jweixin=jweixin
// #endif

// 页面跳转方法
Vue.prototype.$jumpUrl = function (url, Authentication = false) {
	if (Authentication) {
		if (this.$isLogin()) {
			urlTo(url)
		}
	} else {
		urlTo(url)
	}
}
function urlTo(url) {
	if (url === '') {
		return false
	} else if (url === 'isnull') {
		uni.showToast({
			title: '功能建设中,敬请期待！',
			icon: 'none'
		});
	} else if (url.indexOf('http') > -1) {
		// #ifdef MP-WEIXIN
		uni.navigateTo({
			url: url
		})
		// #endif
		// #ifdef H5	
		let host = window.location.host
		if (url.indexOf(host) > -1) {
			uni.navigateTo({
				url: url.split('#')[1]
			})
		} else {
			window.location.href = url
		}
		// #endif
		// #ifdef APP-PLUS
		plus.runtime.openURL(url)
		// #endif
	} else {
		uni.navigateTo({
			url: url
		})
	}
}

Vue.prototype.$tel = function (value) {
	uni.makePhoneCall({
		phoneNumber: value
	})
}

Vue.prototype.$isLogin = function () {
	if (!uni.getStorageSync('userInfo').nickName) {
		uni.showModal({
			title: '提示',
			content: '您还没有登录，请前往登录！',
			success: function (res) {
				if(res.confirm){
					uni.navigateTo({
						url: `/pages/login/index?isBack=1`
					})
				}
			}
		})
		return false
	} else {
		return true
	}
}

Vue.prototype.$getImg = function (value) {
  if (value) {
    return value.split(',').map((t) => {
      t = store.state.ossResourceUrl + t
      return t
    }).join(',')
  } else {
    return require('./static/noimage.png')
  }
  // return value ? base.base.ossResourceUrl + value : require('assets/index/noimage.png')
}
Vue.prototype.$toast=function(title,state){
	uni.showToast({
		title: title,
		icon:"none",
		duration: 2000,
		mask:state || false//是否显示透明蒙层，防止触摸穿透
	});
}
//获取系统信息 
Vue.prototype.$getSystemInfo=function(){
	 uni.getSystemInfo({
		 success:function(res){
			console.log('当前平台？？？？？',res)
			let model=res.model
			if (model.search('iPhoneX') != -1 || model.search('iPhone X') != -1) {
				Vue.prototype.$isIphoneX=true
			} else {
			   Vue.prototype.$isIphoneX=false
			}
			
			if(model.platform=="android"){
				Vue.prototype.$isIphone=false
			}else{
				Vue.prototype.$isIphone=true
			}
			 Vue.prototype.$screenH=res.screenHeight
		 }
	 });
}
Vue.prototype.$getSystemInfo()

const app = new Vue({
	// store,
	...App
})
app.$mount()
